set more off
capture log close
cd *** Fill in path name here ***

//  program:    AnanatEtAl_suicidality results
//  task:	Regressions of suicidal ideation on job loss 

log using *** Fill in file name here ***, replace text

**** ALL CHILDREN ****; 
// #1
// Load data
use AnanatEtAl_suicidality_data.dta, clear

// #2
// Indicate data is weighted
svyset psu [pweight=weight], strata(stratum)  singleunit(certainty) 

// #3 
// Run IV-probit regressions, addressing the complex survey design

svy: ivprobit suicthtly (seppctyrlag = ticpctyrlag) black hisp othrace age female yrd* std*
margins, dydx (seppctyrlag) predict (pr)

clear

**** BLACK CHILDREN ONLY ****; 

// #1
// Load data
use AnanatEtAl_suicidality_data.dta, clear

// #2
// Indicate data is weighted
svyset psu [pweight=weight], strata(stratum)  singleunit(certainty) 

// #3
// Select only black children
keep if black == 1

// #4 
// Run IV-probit regressions, addressing the complex survey design

svy: ivprobit suicthtly (seppctyrlag = ticpctyrlag) age female yrd* std*
margins, dydx (seppctyrlag) predict (pr)

clear

**** WHITE CHILDREN ONLY ****; 
// #1
// Load data
use AnanatEtAl_suicidality_data.dta, clear

// #2
// Indicate data is weighted
svyset psu [pweight=weight], strata(stratum)  singleunit(certainty) 

// #3
// Select only white children
keep if white == 1

// #4 
// Run IV-probit regressions, addressing the complex survey design

svy: ivprobit suicthtly (seppctyrlag = ticpctyrlag) age female yrd* std*
margins, dydx (seppctyrlag) predict (pr)

clear

**** STATE-YEARS WITH BELOW MEDIAN UNEMPLOYMENT ****; 
// #1
// Load data
use AnanatEtAl_suicidality_data.dta, clear

sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag<cutoff


// #2
// Indicate data is weighted
svyset psu [pweight=weight], strata(stratum)  singleunit(certainty) 

// #3 
// Run IV-probit regressions, addressing the complex survey design

svy: ivprobit suicthtly (seppctyrlag = ticpctyrlag) black hisp othrace age female yrd* std*
margins, dydx (seppctyrlag) predict (pr)

clear

**** STATE-YEARS WITH ABOVE MEDIAN UNEMPLOYMENT ****; 

// #1
// Load data
use AnanatEtAl_suicidality_data.dta, clear

sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag>cutoff

// #2
// Indicate data is weighted
svyset psu [pweight=weight], strata(stratum)  singleunit(certainty) 

// #3 
// Run IV-probit regressions, addressing the complex survey design

svy: ivprobit suicthtly (seppctyrlag = ticpctyrlag) black hisp othrace age female yrd* std*
margins, dydx (seppctyrlag) predict (pr)

clear


log close
